package com.iyjhsoc.game.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.iyjhsoc.game.dao.PlayerDAO;
import com.iyjhsoc.game.domain.VO.PlayerVO;
import com.iyjhsoc.game.domain.dto.PlayerDTO;
import com.iyjhsoc.game.domain.entity.PlayerDO;
import com.iyjhsoc.game.domain.response.Response;
import com.iyjhsoc.game.service.PlayerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PlayerServiceImpl extends ServiceImpl<PlayerDAO, PlayerDO> implements PlayerService {
    @Resource
    PlayerDAO playerDAO;
    @Override
    public Response queryList(PlayerVO vo) {
        QueryWrapper<PlayerDO> queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("game_id",vo.getGameId());
        queryWrapper.eq("retire",1);
        List<PlayerDO> list = playerDAO.selectList(queryWrapper);
        return Response.SUCCESS(list);
    }

    @Override
    public Response queryPage(PlayerVO vo) {
        if(StringUtil.isEmpty(vo.getGameId())){
            return Response.ERROR("请选择游戏");
        }
        QueryWrapper<PlayerDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("game_id",vo.getGameId());
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<PlayerDTO> list = playerDAO.queryList(vo);
        return Response.SUCCESS(new PageInfo<>(list));
    }

    @Override
    public Response getPlayerById(String id) {
        PlayerDTO playerById = playerDAO.getPlayerById(id);
        return Response.SUCCESS(playerById);
    }
}
